//
//  MLNewsCell.m
//  keJiNews
//
//  Created by 魔龙 on 16/4/27.
//  Copyright © 2016年 魔龙. All rights reserved.
//

#import "MLNewsCell.h"
#import "UIImageView+WebCache.h"

@interface MLNewsCell()
/**
 *  图片
 */
@property (weak, nonatomic) IBOutlet UIImageView *imgIcon;
/**
 *  标题
 */
@property (weak, nonatomic) IBOutlet UILabel *lblTitle;
/**
 *  描述
 */
@property (weak, nonatomic) IBOutlet UILabel *lblSubtitle;
/**
 *  第二张图片（如果有的话）
 */
@property (weak, nonatomic) IBOutlet UIImageView *imgOther1;
/**
 *  第三张图片（如果有的话）
 */
@property (weak, nonatomic) IBOutlet UIImageView *imgOther2;

@end

@implementation MLNewsCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setNews:(MLNews *)news{
    _news = news;
    [self.imgIcon sd_setImageWithURL:[NSURL URLWithString:self.news.imgsrc] placeholderImage:[UIImage imageNamed:@"302"]];
    self.lblTitle.text = self.news.title;
    self.lblSubtitle.text = self.news.digest;
    
    // 多图cell
    if (self.news.imgextra.count == 2) {
        [self.imgOther1 sd_setImageWithURL:[NSURL URLWithString:self.news.imgextra[0][@"imgsrc"]] placeholderImage:[UIImage imageNamed:@"302"]];
        [self.imgOther2 sd_setImageWithURL:[NSURL URLWithString:self.news.imgextra[1][@"imgsrc"]] placeholderImage:[UIImage imageNamed:@"302"]];
    }
}

#pragma mark - 类方法返回可重用ID
+ (NSString *)idForRow:(MLNews *)news{
    if(news.hasHead && news.photosetID){
        return @"TopImageCell";
    }else if(news.hasHead){
        return @"TopTxtCell";
    }else if (news.imgType){
        return @"BigImageCell";
    }else if (news.imgextra){
        return @"ImagesCell";
    }else{
        return @"NewsCell";
    }
}

#pragma mark - 类方法返回行高
+ (CGFloat)heightForRow:(MLNews *)news{
    if (news.hasHead && news.photosetID) {
        return 245;
    }else if(news.hasHead) {
        return 245;
    }else if(news.imgType) {
        return 170;
    }else if (news.imgextra){
        return 130;
    }else{
        return 80;
    }
}


@end
